package com.zsc.edu.gateway.modules.iot.product.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.zsc.edu.gateway.common.enums.IState;
import com.zsc.edu.gateway.modules.attachment.entity.Attachment;
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Set;


/**
 * @author 15864
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@TableName("iot_product")
@JsonInclude
public class Product extends BaseEntity {
    /**
     * 产品名称
     */
    private String name;
    /**
     * 部门ID
     */
    @TableField(value = "dept_id", fill = FieldFill.INSERT)
    private Long deptId;
    /**
     * 产品类型
     */
    private String productType;

    /**
     * 产品型号
     */
    private String model;

    /**
     * 接入方式
     */
    private LinkType link;

    /**
     * 设备包含的扩展属性，产品不同，设备所包含的属性也略有不同
     */
    @TableField(exist = false)
    private Set<Param> params;

    /**
     * 是否启用/停用
     */
    private Boolean enabled = true;

    /**
     * 产品图标附件ID
     */
    public String iconId;

    /**
     * 产品图标附件
     */
    @TableField(exist = false)
    public Attachment icon;

    /**
     * 产品预览图附件ID
     */
    public String previewId;

    /**
     * 产品预览图附件
     */
    @TableField(exist = false)
    public Attachment preview;

    /**
     * 接入方式
     */
    public enum LinkType implements IEnum<Integer>, IState<LinkType> {
        /**
         * TCP
         */
        TCP(1, "TCP"),
        /**
         * HTTP
         */
        HTTP(2, "HTTP"),
        /**
         * MQTT
         */
        MQTT(3, "MQTT");

        private final int value;
        private final String description;

        LinkType(int value, String description) {
            this.value = value;
            this.description = description;
        }

        @Override
        public Integer getValue() {
            return this.value;
        }

        @Override
        public String toString() {
            return this.description;
        }
    }
}
